package com.houtai.service.admin.operation;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.houtai.base.Page;
import com.houtai.base.RetInfo;
import com.houtai.bean.TsJzAdmin;
import com.houtai.bean.TsJzAdminOperation;
import com.houtai.dao.TsJzAdminOperationDao;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by lizhun on 2017/7/28.
 */
@Service
public class AdminOperationService {
    private static Logger logger = Logger.getLogger(AdminOperationService.class);
    @Autowired
    private TsJzAdminOperationDao tsJzAdminOperationDao;

    public RetInfo findAdminOperationPage(Page page, TsJzAdmin tsJzAdmin) {
        String logInfo = this.getClass().getName() + ":findAdminOperationPage:";
        RetInfo retInfo = new RetInfo();
        logger.info("======" + logInfo + "begin======");
        try {
            PageHelper.startPage(page.getCurrent_page(), page.getPage_size(), "id desc");
            List<TsJzAdminOperation> lists = tsJzAdminOperationDao.findTsJzAdminOperation(page);
            PageInfo<TsJzAdminOperation> list = new PageInfo<>(lists);
            Map<String, Object> map = new HashMap<>();
            map.put("list", list.getList());
            map.put("pages", list.getPages());
            map.put("total_record", list.getTotal());
            map.put("current_page", list.getPageNum());
            map.put("page_size", list.getPageSize());
            retInfo.setMark("0");
            retInfo.setTip("成功");
            retInfo.setObj(map);
            TsJzAdminOperation operation = new TsJzAdminOperation();
            operation.setAdmin_name(tsJzAdmin.getUser_name());
            operation.setAdmin_operation("查看操作日志列表，页数：" + page.getCurrent_page());
            tsJzAdminOperationDao.insert(operation);
        } catch (Exception e) {
            logger.error("======error:" + e.toString() + "======");
            retInfo.setMark("-1");
            retInfo.setTip("系统错误");
        }
        logger.info("======" + logInfo + "end======");

        return retInfo;
    }



}
